# -*- coding: utf-8 -*-
"""
Created on Tue Apr 16 12:08:15 2024

@author: 29865
"""

import pandas as pd
import numpy as np
data = {'a': [2, 2, np.nan, 5, 6], 
        'b': ['kl', 'kl', 'kl', np.nan, 'kl'], 
        'c': [4, 6, 5, np.nan, 6], 
        'd': [7, 9, np.nan, 9, 8]}
df = pd.DataFrame(data)

# 使用一个固定的值填充所有 NaN  
df_filled = df.fillna(0)  

# 使用不同的值填充不同列的 NaN  
df_filled_dict = df.fillna({'a': 0, 'b': 1, 'c': 2})  